<template>
  <el-dialog :title="!form.id ? '新增' : '修改'" :visible.sync="visible" :close-on-click-modal="false" width="70%" top="10vh">
    <div class="sketch_content">
      <el-form :model="form" label-width="120px" ref="dataForm">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="名称" prop="name" :rules="rules.isRange('1-255')">
              <el-input v-model="form.name" placeholder="请输入名称" maxlength="255" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="联系人" prop="linkMan" :rules="rules.isRange('1-64')">
              <el-input v-model="form.linkMan" placeholder="请输入联系人" maxlength="64" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="手机号码" prop="phone" :rules="rules.isPhone">
              <el-input v-model="form.phone" placeholder="请输入手机号码" maxlength="20" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="邮箱" prop="email" :rules="rules.isEmail">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="128" show-word-limit/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="状态" prop="status" :rules="rules.isNotNull">
              <el-radio-group v-model="form.status">
                <el-radio :label="1">停用</el-radio>
                <el-radio :label="2">正常</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="有效开始时间" prop="startTime" :rules="rules.isNotNull">
              <el-date-picker style="width: 100%" v-model="form.startTime" type="date"
                value-format="yyyy-MM-dd" placeholder="请选择有效开始时间"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="有效截止时间" prop="endTime" :rules="rules.isNotNull">
              <el-date-picker style="width: 100%" v-model="form.endTime" type="date"
                value-format="yyyy-MM-dd" placeholder="请选择有效截止时间"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" maxlength="64" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" icon="el-icon-close" @click.native="visible = false">取消</el-button>
      <el-button size="small" icon="el-icon-check" type="primary" :loading="isDisabled"
        @click.native="saveOrUpdate(form, '/sysTenant/save', '/sysTenant/update')">确定
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        rules: this.getRules(),
        isDisabled: false,
        form: {
          code: '',
          name: '',
          linkMan: '',
          phone: '',
          email: '',
          startTime: '',
          endTime: '',
          remark: '',
          status: 1,
          flag: 1
        }
      }
    },
    methods: {
      init (id) {
        this.visible = true
        this.isDisabled = false
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
        this.form.id = id
        if (id) {
          this.httpGet(`/sysTenant/info/${id}`).then(res => {
            this.form = res.data
          })
        } else {
        }
      }
    }
  }
</script>

